package com.woniu.car.controller;


import com.woniu.car.common.ResponseEntity;
import com.woniu.car.dto.CouponUseDto;
import com.woniu.car.entity.TCouponReceive;
import com.woniu.car.properties.StatisticsProperties;
import com.woniu.car.service.TCouponReceiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuyanzu
 * @since 2021-06-22
 */
@RestController
@Api(tags = "用户查询优惠券控制层")
@Slf4j
public class TCouponReceiveController {
    @Autowired
    private TCouponReceiveService receiveService;
    
    @GetMapping("/searchUserCoupon")
    @ApiOperation("用户查询自己优惠券")
    public List<TCouponReceive> searchUserCoupon(@RequestHeader("userId") Integer userId) throws Exception {
        List<TCouponReceive> list = receiveService.searchUserCoupon(userId);
        return list;
    }
    @DeleteMapping("/DeleteUserCoupon")
    @ApiOperation("用户使用优惠券后删除")
    public ResponseEntity deleteUserCoupon(Integer couponReceiveId) throws Exception {
        receiveService.deleteUserCoupon(couponReceiveId);
        return new ResponseEntity().setCode(StatisticsProperties.SUCCESSCODE).setMsg(StatisticsProperties.SUCCESSMSG);
    }
    @GetMapping("/couponUseCoupon")
    @ApiOperation("用户使用优惠券后返回参数给其他服务作日志")
    ResponseEntity<CouponUseDto> couponUseCoupon(Integer couponReceiveId) throws Exception{
        return ResponseEntity.builder(CouponUseDto.class).setCode(StatisticsProperties.SUCCESSCODE).setMsg(StatisticsProperties.SUCCESSMSG)
                                    .setObject(receiveService.couponUseCoupon(couponReceiveId));
    }
    
}

